package br.com.ilha.dao;

import java.util.List;

import org.hibernate.Session;

import br.com.ilha.bean.Lei;
import br.com.ilha.hibernate.HibernateUtil;

public class LeiDao {

	private Session session;
	
	public LeiDao() {
		this.session = new HibernateUtil().getSession();
	}

	public static void adiciona(Lei lei) {
		Session session = new HibernateUtil().getSession();
		session.beginTransaction();
		session.save(lei);
		session.getTransaction().commit();
		System.out.println("ID da Lei="+lei.getId());
		session.close();
	}

	public LeiDao(Session session) {
		this.session = session;
	}

	public void salva(Lei lei) {
		this.session.save(lei);
	}
	public void remove(Lei lei) {
		this.session.delete(lei);
	}
	public Lei procura(Long id) {
		return (Lei) this.session.load(Lei.class, id);
	}
	public void atualiza(Lei lei) {
		this.session.update(lei);
	}
	
	public List<Lei> listAll(){
		return this.session.createCriteria(Lei.class).list();
	}


}
